<style>
#same-address,#same-father,#same-mother {border: #000 solid 1px ; background:#ffa; margin: 0 5px;}
</style>
<script type="text/javascript">
<!--
$(document).ready(function(){

	$("#address-label").append('<input id="same-address"  type="button" value="<?php echo $this->translate('same as registered_address')?>"/>');
	$("#same-address").click(function(){
		var sn = $("#student_sn").val();
		$.getJSON('<?php echo $this->route('getaddress')?>',{sn:sn},function(data){
			$("#guardian-address").attr('value',data.registered_address);
		});
	});

	$("#same-father").click(function(){copyParent('M')});
	$("#same-mother").click(function(){copyParent('F')});


	function copyParent(sex) {
		var boy = $("#student_sn option:selected").hasClass('option_boy');
		if (sex=='M') {
			var name = 'parentsM';
			if (boy)
				$("#guardian-relation").val(1);
			else
				$("#guardian-relation").val(2);
		}
		else {
			var name = 'parentsF';
			if (boy)
				$("#guardian-relation").val(3);
			else
				$("#guardian-relation").val(4);
		}

		$("#guardian-name").attr('value',$("#"+name+"-name").attr('value'));
		$("#guardian-identification_number").attr('value',$("#"+name+"-identification_number").attr('value'));
		$("#guardian-organ").attr('value',$("#"+name+"-organ").attr('value'));
		$("#guardian-organ_title").attr('value',$("#"+name+"-organ_title").attr('value'));
		$("#guardian-phone_office").attr('value',$("#"+name+"-phone_office").attr('value'));
		$("#guardian-phone_mobile").attr('value',$("#"+name+"-phone_mobile").attr('value'));
		$("#guardian-email").attr('value',$("#"+name+"-email").attr('value'));
	}

	$("#setForm").ajaxForm({
    	dataType:  'json',
    	success: showResponse
    });

	function showResponse(res) {
		if (!res.success) {
			var message = '';
			$.each(res.error,function(i,v){
				$.each(v,function(ii,vv){
    					$("#"+i+"-"+ii).addClass('ui-state-error');
    					$.each(vv,function(iii,vvv){
    						message += $("#"+ii+"-label label").html()+': '+ vvv+ "\n";
    					});
				});
			});
			jAlert(message, '<?php echo $this->translate('checking errors')?>');
		}
		else{
			$(".ui-state-error").removeClass('ui-state-error ');
			// 判斷下一位
    		if ($("#next_student").attr('checked')){
    			var ss = $("#student_sn option:selected").next();
    			if (ss) {
    				$(ss).attr('selected','selected');
    				getdata($("#student_sn").val());
    			}
    		}
		}
		$('#main_body').unblock();
	}
});
//-->
</script>
<div id="main_body">
<form action="<?php echo $this->route('set')?>" method="post" id="setForm" >
<fieldset class="ui-widget ui-widget-content ui-corner-all"  style="float:left;">
<legend class="ui-widget ui-widget-header ui-corner-all" ><?php echo  $this->translate('father data')?></legend>
<?php echo $this->parentsM->name?>
<?php echo $this->parentsM->alive?>
<?php echo $this->parentsM->english_name?>
<?php echo $this->parentsM->born_year?>
<?php echo $this->parentsM->birthday?>
<?php echo $this->parentsM->nationality?>
<?php echo $this->parentsM->denizened?>
<?php echo $this->parentsM->identification_number?>
<?php echo $this->parentsM->education_level?>
<?php echo $this->parentsM->graduate_kind?>
<?php echo $this->parentsM->occupation?>
<?php echo $this->parentsM->organ?>
<?php echo $this->parentsM->organ_title?>
<?php echo $this->parentsM->phone_home?>
<?php echo $this->parentsM->phone_office?>
<?php echo $this->parentsM->phone_mobile?>
<?php echo $this->parentsM->email?>
<?php echo $this->parentsM->website?>
<?php echo $this->parentsM->sn?>
<?php echo $this->parentsM->student_sn?>
</fieldset>
<fieldset class="ui-widget ui-widget-content ui-corner-all"  style="float:left;">
<legend class="ui-widget ui-widget-header ui-corner-all" ><?php echo  $this->translate('mother data')?></legend>
<?php echo $this->parentsF->name?>
<?php echo $this->parentsF->alive?>
<?php echo $this->parentsF->english_name?>
<?php echo $this->parentsF->born_year?>
<?php echo $this->parentsF->birthday?>
<?php echo $this->parentsF->nationality?>
<?php echo $this->parentsF->denizened?>
<?php echo $this->parentsF->identification_number?>
<?php echo $this->parentsF->education_level?>
<?php echo $this->parentsF->graduate_kind?>
<?php echo $this->parentsF->occupation?>
<?php echo $this->parentsF->organ?>
<?php echo $this->parentsF->organ_title?>
<?php echo $this->parentsF->phone_home?>
<?php echo $this->parentsF->phone_office?>
<?php echo $this->parentsF->phone_mobile?>
<?php echo $this->parentsF->email?>
<?php echo $this->parentsF->website?>
<?php echo $this->parentsF->sn?>
<?php echo $this->parentsF->student_sn?>
</fieldset>

<div style="float:left">
<fieldset class="ui-widget ui-widget-content ui-corner-all" >
<legend class="ui-widget ui-widget-header ui-corner-all" ><?php echo  $this->translate('guardian data')?>
<input type="button" id="same-father" value="<?php echo $this->translate('same as father')?>"/>
<input type="button" id="same-mother" value="<?php echo $this->translate('same as mother')?>"/>
</legend>
<?php echo $this->guardian->name?>
<?php echo $this->guardian->relation?>
<?php echo $this->guardian->address?>
<?php echo $this->guardian->identification_number?>
<?php echo $this->guardian->organ?>
<?php echo $this->guardian->organ_title?>
<?php echo $this->guardian->phone_office?>
<?php echo $this->guardian->phone_mobile?>
<?php echo $this->guardian->email?>
<?php echo $this->guardian->sn?>
<?php echo $this->guardian->student_sn?>
</fieldset>

<fieldset class="ui-widget ui-widget-content ui-corner-all" >
<legend class="ui-widget ui-widget-header ui-corner-all" ><?php echo  $this->translate('grandfather data')?></legend>
<?php echo $this->grandparentsM->name?>
<?php echo $this->grandparentsM->alive?>
<?php echo $this->grandparentsM->sn?>
<?php echo $this->grandparentsM->student_sn?>
</fieldset>

<fieldset class="ui-widget ui-widget-content ui-corner-all" >
<legend class="ui-widget ui-widget-header ui-corner-all" ><?php echo  $this->translate('grandmother data')?></legend>
<?php echo $this->grandparentsF->name?>
<?php echo $this->grandparentsF->alive?>
<?php echo $this->grandparentsF->sn?>
<?php echo $this->grandparentsF->student_sn?>
</fieldset>
</div>
</form>
</div>
<div style="clear:both;"></div>
